package interviewClassic150;

import org.junit.Test;

public class Rotate {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        //反转整个数组
        reverse(nums,0,n);
        //反转前k个数组
        reverse(nums,0,k);
        //反转后面n-k
        reverse(nums,k,n);
    }

    private void reverse(int[] nums, int start, int end) {
        int left = start;
        int right = end - 1;
        while (left < right) {
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }
    }

    @Test
    public void test() {
        int[] nums = {1,2,3,4,5,6,7};
        rotate(nums,3);
        System.out.println(nums);
    }


}
